from PySide6.QtWidgets import QStackedWidget
from ..base.widget import TgBaseWidget
from ..layouts.vbox_layout import TgVBoxLayout
from .bottom_nav_bar import TgBottomNavBar

class NavViewWidget(TgBaseWidget):
    """A widget with a content area and a bottom navigation bar."""

    def __init__(self, parent=None):
        super().__init__(parent)
        self._layout = TgVBoxLayout(self, margins="none", spacing="none")

        # Content area with stacked layout
        self.pages = QStackedWidget()
        self._layout.addWidget(self.pages, 1)

        # Bottom navigation bar
        self.bottom_nav = TgBottomNavBar(height='high')
        self._layout.addWidget(self.bottom_nav)

    def add_item(self, widget, name, icon=None):
        """Adds a widget to the content area and a corresponding button to the nav bar."""
        index = self.pages.addWidget(widget)
        self.bottom_nav.add_item(
            text=name,
            icon=icon,
            on_click=lambda: self.pages.setCurrentIndex(index)
        )